package com.netease.nie.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.netease.nie.dao.CreditDao;
import com.netease.nie.dao.CreditHistoryDao;
import com.netease.nie.dao.RobGoodsInfoPeriodDao;
import com.netease.nie.dao.RobGoodsPeriodPersonTimeDao;
import com.netease.nie.dto.RobGoodsTransactionalDto;

@Service
public class GoodsRobServiceImpl implements GoodsRobService {

	@Autowired
	private CreditDao creditDao;
	
	@Autowired
	private CreditHistoryDao creditHistoryDao;
	
	@Autowired
	private RobGoodsPeriodPersonTimeDao robGoodsPeriodPersonTimeDao;
	
	@Autowired
	private RobGoodsInfoPeriodDao robGoodsInfoPeriodDao;

	@Transactional(rollbackFor = Exception.class)
	public void updateGoodsRobStatus(RobGoodsTransactionalDto robGoodsTransactionalDto)
			throws Exception {
		robGoodsInfoPeriodDao.updateRobGoodsPeriod(robGoodsTransactionalDto.getRobGoodsInfoPeriod());
		robGoodsPeriodPersonTimeDao.insertRobGoodsPeriodPersonTime(robGoodsTransactionalDto.getRobGoodsPeriodPersonTime());
		creditDao.deductUserCredit(robGoodsTransactionalDto.getCredit());
		creditHistoryDao.insertCreditHistory(robGoodsTransactionalDto.getCreditHistory());
	}

}
